import {AnyObject} from "./interface.ts";

export function pick(object: AnyObject, path: string | string[]) {
  if (typeof path === "string") {
    return pickBy(getPaths(path))
  }
  return pickBy(path)

  /**
   * @param path
   */
  function getPaths(path: string) {
    return path.split(".");
  }
  /**
   * @param path
   */
  function pickBy(path:string[]) {
    return path.reduce((acc, path) => {
      return acc[path];
    }, object);
  }
}
